package com.atwulidun.factory02.abstractfactory.order;

import com.atwulidun.factory02.abstractfactory.pizza.Pizza;
import com.atwulidun.factory02.abstractfactory.sausage.Sausage;

import java.util.Scanner;

public class OrderFood {
    // 把CheeseFactory和PepperFactory聚合进来
    private Factory cheeseFactory;
    private Factory pepperFactory;
    private Scanner scanner = new Scanner(System.in);

    public OrderFood(Factory cheeseFactory, Factory pepperFactory) {
        this.cheeseFactory = cheeseFactory;
        this.pepperFactory = pepperFactory;
        orderFood();
    }

    private void orderFood() {
        String input = null;
        while (true) {
            System.out.println("请输入食物种类：");
            input = scanner.next();
            if (input.equals("pizza")) {
                while (true) {
                    System.out.println("请输入食物口味：");
                    input = scanner.next();
                    Pizza pizza;
                    if (input.equals("cheese")) {
                        pizza = cheeseFactory.createPizza();
                        pizza.prepare();
                        pizza.bake();
                        pizza.cut();
                        pizza.bake();
                        break;
                    } else if (input.equals("pepper")) {
                        pizza = pepperFactory.createPizza();
                        pizza.prepare();
                        pizza.bake();
                        pizza.cut();
                        pizza.bake();
                        break;
                    }
                }
            } else if (input.equals("sausage")) {
                while (true) {
                    System.out.println("请输入食物口味：");
                    input = scanner.next();
                    Sausage sausage;
                    if (input.equals("cheese")) {
                        sausage = cheeseFactory.createSausage();
                        sausage.prepare();
                        sausage.bake();
                        sausage.cut();
                        sausage.bake();
                        break;
                    } else if (input.equals("pepper")) {
                        sausage = pepperFactory.createSausage();
                        sausage.prepare();
                        sausage.bake();
                        sausage.cut();
                        sausage.bake();
                        break;
                    }
                }
            }
        }
    }
}
